package com.highcom.common;

import com.highcom.config.RedisConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import redis.clients.jedis.JedisPool;

import javax.annotation.PostConstruct;
import java.util.Set;

/**
 * @version 1.0
 * @Author YangJiaQuan_hrbnu
 * @Date 2024/8/2 9:39
 */

@EnableScheduling
@SpringBootApplication
public class ScheDelPic {
    private static JedisPool jedisPool;
    @Autowired
    private RedisConfig redisConfig;
    @PostConstruct
    public void init(){
        jedisPool = redisConfig.redisPoolFactory();
    }


    @Scheduled(cron = "0 0/2 * * * ? ")
    public void deletePicJob(){
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (set != null){
            for (String picname : set) {
                QiniuUtils.deleteFileFromQiniu(picname);
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,picname);
                System.out.println("定时任务执行，清理垃圾图片："+picname);
            }
        }
    }

}
